//
//  MyCouponListCell.m
//  BaseProject
//
//  Created by 王洋 on 2020/7/21.
//  Copyright © 2020 王洋. All rights reserved.
//

#import "MyCouponListCell.h"

@implementation MyCouponListCell

- (void)awakeFromNib {
    [super awakeFromNib];
}

- (void)layoutSubviews {
    [super layoutSubviews];
    
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [self.actionBtn pp_clipCorners:UIRectCornerAllCorners radius:self.actionBtn.frame.size.height/2];
        [self.couponLogo pp_clipCorners:UIRectCornerAllCorners radius:5];

    });
}

- (void)fillCellWithModel:(CommonCouponModel *)model {
    
    self.discountLab.text = [Utilities changeDoubleToString:model.scoCut];
    
    if (model.scoFull == 0) {
        self.conditionLab.text = @"无门槛";
    } else {
        self.conditionLab.text = [NSString stringWithFormat:@"满%@可用",[Utilities changeDoubleToString:model.scoFull]];
    }

    
    self.couponTimeLab.text = [NSString stringWithFormat:@"%@-%@",model.scoEffectiveStartime,model.scoEffectiveEndtime];

    //优惠券使用状态
    switch (model.status) {//领取津贴的状态（1：未使用，2：已使用，3：已过期）
        case 1:{
            self.actionBtn.hidden = NO;
            self.tagImgv.hidden = YES;
            self.coverView.hidden = YES;
            [self.actionBtn setTitle:@"去使用" forState:UIControlStateNormal];
        } break;
        case 2:{
            self.actionBtn.hidden = YES;
            self.tagImgv.hidden = NO;
            self.coverView.hidden = NO;
            [self.tagImgv setImage:[UIImage imageNamed:@"tag_used"]];
        } break;
        case 3:{
            self.actionBtn.hidden = YES;
            self.tagImgv.hidden = NO;
            self.coverView.hidden = NO;
            [self.tagImgv setImage:[UIImage imageNamed:@"tag_over"]];

        } break;
        default:{
            self.actionBtn.hidden = YES;
            self.tagImgv.hidden = YES;
            self.coverView.hidden = YES;

        } break;
    }
    

    self.tagLab.hidden = NO;//¥的显示和隐藏
    self.couponTypeLab.text = model.typeName;

    //优惠券类型
    switch (model.scoType) {
        case CouponType_all:{

            [self.couponLogo setImage:[UIImage imageNamed:@"logo_all"]];
            self.couponTitleLab.text = model.scoName;

        } break;
        case CouponType_industry:{//行业
            [self.couponLogo setImage:[UIImage imageNamed:@"logo_industry"]];
            self.couponTitleLab.text = model.scoName;

        } break;
        case CouponType_union:{
            [self.couponLogo setImage:[UIImage imageNamed:@"logo_union"]];
//            self.couponTitleLab.text = @"无忧选商家券";
            self.couponTitleLab.text = model.scoName;

        } break;
        case CouponType_userNew:{
            [self.couponLogo setImage:[UIImage imageNamed:@"logo_all"]];
            self.couponTitleLab.text = model.scoName;
            self.discountLab.text = @"免单";
            self.tagLab.hidden = YES;

        } break;
        case CouponType_storeAll:{
//            self.couponLogo
            //网络图
            NSString *url = [TT_OSSManager reSourceUrl:model.logoUrl type:BA_resizeType_plus];
            [self.couponLogo sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            self.couponTitleLab.text = model.sellerName;

        } break;
        case CouponType_storeProduct:{
//            self.couponLogo
            //网络图
            NSString *url = [TT_OSSManager reSourceUrl:model.logoUrl type:BA_resizeType_plus];
            [self.couponLogo sd_setImageWithURL:[NSURL URLWithString:url] placeholderImage:[UIImage imageNamed:@"placeholder"]];
            self.couponTitleLab.text = model.sellerName;

        } break;
        default:{
            [self.couponLogo setImage:[UIImage imageNamed:@"logo_all"]];
            self.couponTitleLab.text = model.scoName;

        } break;
    }
    
    //优惠券的状态0:全部1：待生效2：已生效3：已过期4:可领取
    if (model.couponType == 4) {
        self.actionBtn.hidden = NO;
        [self.actionBtn setTitle:@"领取" forState:UIControlStateNormal];
    }
    
    
    [self.couponBGImgV setImage:[UIImage imageNamed:@"coupon_bg"]];

}

@end
